<template>
  <div>
    <!--    工具页面-->
    <SafeTools v-bind:type_info="'添加'" v-bind:multipleSelection="multipleSelection" @listData='listData' />
    <SafeTools ref="tools_box" v-bind:type_info="'编辑'" v-bind:edit_form="info" @listData='listData' />
    <!--    展示页面-->
    <el-table size='mini' :data="server_list" tooltip-effect="dark" :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column prop="id" label="id">
        <template slot-scope="scope">
          {{scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column prop="name" :label="$t('对象名称')">
      </el-table-column>
      <el-table-column prop="iface" :label="$t('接口集合')">
      </el-table-column>
      <el-table-column prop="desc" :label="$t('描述')">
      </el-table-column>
      <el-table-column prop="ref" :label="$t('引用计数')">
      </el-table-column>
      <el-table-column prop="sys" fixed="right" :label="$t('操作')">
        <template slot-scope="scope">
          <el-button type="success" plain size="mini" :class="'edit' + scope.$index" @click="get_info(scope.row)">
            {{$t('编辑')}}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
import SafeTools from './components/SafeTools'
import { getSafeArray, getSafeInfo } from '@/api/list/safe'
export default {
  name: 'Safe',
  components: {
    SafeTools
  },
  data () {
    return {
      server_list: [],
      info: {},
      editVisible: false,
      multipleSelection: []
    }
  },
  mounted () {
    this.listData()
  },
  methods: {
    listData () {
      getSafeArray().then(response => {
        this.server_list = response.info
      })
    },
    change (data) {
      this.editVisible = data
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    handel_array (row) {
      let test = ''
      row.member.forEach((item, index, array) => {
        if (index === row.member.length - 1) {
          test += item
        } else {
          test += item + ','
        }
      })
      return test
    },
    handel_weekdays_array (row) {
      let test = ''
      row.weekdays.forEach((item, index, array) => {
        if (index === row.weekdays.length - 1) {
          test += item
        } else {
          test += item + ','
        }
      })
      return test
    },
    handel_monthdays_array (row) {
      let test = ''
      row.monthdays.forEach((item, index, array) => {
        if (index === row.monthdays.length - 1) {
          test += item
        } else {
          test += item + ','
        }
      })
      return test
    },
    get_info (row) {
      let formData = {}
      formData.name = row.name
      getSafeInfo(formData).then(response => {
        this.info = response.info[0]
        this.$refs.tools_box.edit_info()
      })
    }
  }
}
</script>

<style scoped>
</style>
